# -*- coding: utf-8 -*-
# ㊎ Author : XMZ
# ㊍ Date:  : 2023/12/21 17:11
# ㊌ File   : script-framework->sqllite3_example.py
# ㊋ IDE    : PyCharm
# ㊏ REMARKS:
import os
import sys
import sqlite3

path = os.path.abspath(__file__)
sys.path.extend([path, os.path.dirname(path), os.path.dirname(os.path.dirname(path))])
from core.config import Settings

# 连接数据库
connection = sqlite3.connect(Settings.sql_lite_db)  # 这里 'example.db' 是数据库文件的路径或名称

# 创建游标
cursor = connection.cursor()

# 示例：创建表格
cursor.execute('''CREATE TABLE IF NOT EXISTS users (
                    id INTEGER PRIMARY KEY,
                    name TEXT,
                    age INTEGER
                )''')

# 示例：插入数据
cursor.execute("INSERT INTO users (name, age) VALUES (?, ?)", ('Alice', 30))
cursor.execute("INSERT INTO users (name, age) VALUES (?, ?)", ('Bob', 25))

# 示例：查询数据
cursor.execute("SELECT * FROM users")
rows = cursor.fetchall()
for row in rows:
    print(row)

# 提交并关闭连接
connection.commit()
connection.close()
